package Graph_10;

/*
 * @Author 罗
 * @date 2020/3/27 - 7:14 下午
 *
 */

import org.junit.Test;

public class test {

    public static void main(String[] args) {
        Graph graph = new Graph(5);
        graph.addVertex("a");
        graph.addVertex("b");
        graph.addVertex("c");
        graph.addVertex("d");
        graph.addVertex("e");
        graph.addEdge("a", "b", 1);
        graph.addEdge("a", "c", 1);

        graph.addEdge("b", "a", 1);

        graph.addEdge("b", "c", 1);
        graph.addEdge("b", "d", 1);

        graph.addEdge("b", "e", 1);


        graph.show();

        System.out.println("深度优先遍历----->");
        graph.depthFirstSearch();
        System.out.println("图的广度优先遍历-->");
        graph.broadFirstSearch();
        System.out.println("\n升级广度优先遍历-->");
        graph.bfsEnhance();
    }

    /**
     * 深度优先遍历dfs和广度优先bfs遍历的区别
     */
    @Test
    public void differenceOfBfsAndDfs() {
        Graph graph = new Graph(10);
        graph.addVertex("1");
        graph.addVertex("2");
        graph.addVertex("3");
        graph.addVertex("4");
        graph.addVertex("5");
        graph.addVertex("6");
        graph.addVertex("7");
        graph.addVertex("8");

        graph.addEdge("1", "2", 1);
        graph.addEdge("1", "3", 1);

        graph.addEdge("2", "4", 1);

        graph.addEdge("2", "5", 1);

        graph.addEdge("4", "8", 1);

        graph.addEdge("5", "8", 1);
        graph.addEdge("3", "6", 1);

        graph.addEdge("7", "3", 1);
        graph.addEdge("7", "6", 1);

        System.out.println("深度优先遍历");
        graph.depthFirstSearch();
        System.out.println("广度优先遍历");
        graph.bfsEnhance();
        graph.show();
    }
}
